<%--
  Created by IntelliJ IDEA.
  User: aa
  Date: 2019/07/23
  Time: 16:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="ch-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" href="${APP_PATH}/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${APP_PATH}/css/font-awesome.min.css">
    <link rel="stylesheet" href="${APP_PATH}/css/main.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor: pointer;
        }

        table tbody tr:nth-child(odd) {
            background: #F4F4F4;
        }

        table tbody td:nth-child(even) {
            color: #C00;
        }
    </style>
</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <div><a class="navbar-brand" style="font-size:32px;" href="#">众筹平台 - 角色维护</a></div>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <%--头部导航栏--%>
            <jsp:include page="/WEB-INF/jsp/common/headShow.jsp"></jsp:include>
            <form class="navbar-form navbar-right">
                <input type="text" class="form-control" placeholder="Search...">
            </form>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <div class="tree">
                <%--左方功能树导航栏,静态包含--%>
                <%@ include file="/WEB-INF/jsp/common/menu.jsp" %>
            </div>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <input class="form-control has-success" type="text" placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button type="button" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询
                        </button>
                    </form>
                    <button type="button" class="btn btn-danger" style="float:right;margin-left:10px;"><i
                            class=" glyphicon glyphicon-remove"></i> 删除
                    </button>
                    <button type="button" class="btn btn-primary" style="float:right;"
                            onclick="window.location.href='form.html'"><i class="glyphicon glyphicon-plus"></i> 新增
                    </button>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table id="table_from" class="table  table-bordered">
                            <thead>
                            <tr>
                                <th width="30">#</th>
                                <th width="30"><input type="checkbox"></th>
                                <th>名称</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            </tbody>
                            <tfoot>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${APP_PATH}/jquery/jquery-2.1.1.min.js"></script>
<script src="${APP_PATH}/bootstrap/js/bootstrap.min.js"></script>
<script src="${APP_PATH}/script/docs.min.js"></script>
<%--调用菜单点击js--%>
<script src="${APP_PATH}/script/menu.js"></script>
<script type="text/javascript" src="${APP_PATH}/jquery/layer/layer.js"></script>
<script type="text/javascript">
    $(function () {
        $(".list-group-item").click(function () {
            if ($(this).find("ul")) {
                $(this).toggleClass("tree-closed");
                if ($(this).hasClass("tree-closed")) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
        showMenu();
        queryAllRole();

    });



    //查询全部的role
    function queryAllRole() {
        $.ajax({
            type: "POST",
            data: "",
            url: "${APP_PATH}/role/doQueryAllRole.do",
            beforeSend: function () {
                return true;
            },
            success: function (reslut) {
                if(reslut.success){
                    build_table_body(reslut);
                }else {

                }
            },
            error: function () {
                layer.msg("未知错误");
            }
        });
    }
    function build_table_body(result) {
        $("#table_from tbody").empty();
        var roles = result.roles;
        $.each(roles,function (index, item) {
            var number = $("<td></td>").append(index+1);

            var checkboxInput = $("<input></input>").attr({"type":"checkbox","id":item.id});
            var checkbox = $("<td></td>").append(checkboxInput);

            var roleName = $("<td></td>").append(item.name);

            var assignRoleBtn = $("<button></button>").addClass("btn btn-success btn-xs").attr({"type":"button","onclick":"assignRoleBtn("+item.id+")"})
                .append($("<i></i>").addClass("glyphicon glyphicon-check"));

            var editRoleBtn = $("<button></button>").addClass("btn btn-primary btn-xs").attr({"type":"button","onclick":"editRoleBtn("+item.id+")"})
                .append($("<i></i>").addClass("glyphicon glyphicon-pencil"));

            var deleteRoleBtn =  $("<button></button>").addClass("btn btn-danger btn-xs").attr({"type":"button","onclick":"deleteRoleBtn("+item.id+")"})
                .append($("<i></i>").addClass("glyphicon glyphicon-remove"));

            var groupBtn = $("<td></td>").append(assignRoleBtn).append(" ").append(editRoleBtn).append(" ").append(deleteRoleBtn);

            $("<tr></tr>").append(number).append(checkbox).append(roleName).append(groupBtn).appendTo("#table_from tbody");
        });
    }
    //点击分配角色按钮
    function assignRoleBtn(id){
        window.location.href = "${APP_PATH}/role/toAssignPermission.htm?roleId="+id;
    }
    //点击编辑角色按钮
    function editRoleBtn(id){

    }
    //点击删除角色按钮
    function deleteRoleBtn(id){

    }



    $("tbody .btn-success").click(function () {
        window.location.href = "assignPermission.html";
    });

</script>
</body>
</html>
